<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <title>Pricebook</title>

    </h:head>
    <f:view beforePhase="#{UserDisplayManagedBean.doDisplay}">
        <f:view beforePhase="#{PricebookManagedBean.initView}">
            <h:body>      

                <h:form prependId="false">
                    <!-- IDLE DIALOG for -->
                    <p:confirmDialog message="You have been idle for 5 minutes. Do you want to continue?"  
                                     showEffect="bounce" hideEffect="explode"  
                                     header="Warning message" severity="alert" widgetVar="confirmation">  
                        <p:commandButton value="Yes" onclick="confirmation.hide()" type="button" /> 
                        <p:commandButton value="No" update="panel" oncomplete="confirmation.hide()"  
                                         actionListener="#{UserManagedBean.doLogout}" /> 
                    </p:confirmDialog>

                    <p:idleMonitor timeout="300000" onidle="confirmation.show()" />  
                    <!--END OF IDLE DIALOG-->

                    <p:growl id="msgs" showDetail="true"/>
                   <div id="top" class="top" style="margin-top:0%; margin-bottom:0%">
                        <h:graphicImage value="/image/newHeader.jpg"/>
                        <p:ajaxStatus style="width:16px;height:16px;">
                            <f:facet name="start">
                                <h:graphicImage value="25(2).gif" />
                            </f:facet>
                            <f:facet name="complete">
                                <h:outputText value="" />
                            </f:facet>
                        </p:ajaxStatus>
                        <!--  <hr size="5" style="width:100%;color: lavender;background-color: lavender;margin-top:0%;margin-bottom:0%;border-style:none" noshade="blue"/>
                        -->
                    </div>
                    <div id="content" style="font-family:Tahoma;font-size:11px">

                        <table style="width:100%">
                            <tr>
                                <td style="width:200px">
                                    <p:toolbar style="font-size:100%;margin-top:0%;height:30px;width:200px"> 
                                        <p:toolbarGroup align="right" >
                                            <p:button title="Home" image="ui-icon-home" outcome="SalesDeptWorkspace"/>                                  
                                            <p:button title="Notes" image="ui-icon-note" outcome="tasks"/>                                    
                                            <p:button title="Mail" outcome="messages" image="ui-icon-mail-closed"/>                                    
                                            <p:button title="Edit Preferences" image="ui-icon-gear"/>                                   
                                            <p:button title="Help" image="ui-icon-help"/>
                                            <p:commandButton title="Log Out" immediate="true" type="submit" image="ui-icon-close" actionListener="#{UserManagedBean.doLogout}"/> 
                                        </p:toolbarGroup>
                                    </p:toolbar></td>
                                <td>
                                    <h:graphicImage value="book.png" style="width:40px;height:40px" />
                                    <h:outputText value="         "/>
                                    <h:outputText value="Pricebooks" style="font-family:Tahoma;font-size:20px;font-weight:bolder"/>
                                    <p:spacer width="100" height="10"/>
                                </td>
                            </tr>
                            <tr>
                                <td style="vertical-align:top">
                                    <p:menu style="width:200px;font-size: 12px;font-family: Tahoma;border-style: ridge">  
                                        <p:submenu label="Sales Force Automation" >  
                                            <p:menuitem value="Customers" url="http://localhost:8080/MerlionERP-war/CRM/customers.xhtml" ajax="false" icon="ui-icon ui-icon-person"/>  
                                            <p:menuitem value="Contacts" url="http://localhost:8080/MerlionERP-war/CRM/contacts.xhtml" ajax="false" icon="ui-icon ui-icon-person" />
                                            <p:menuitem value="Leads" url="http://localhost:8080/MerlionERP-war/CRM/salesLeads.xhtml" ajax="false" icon="ui-icon ui-icon-person" />
                                        </p:submenu>
                                        <p:submenu label="Sales Order Processing">
                                            <p:menuitem value="Pricebooks" url="http://localhost:8080/MerlionERP-war/CRM/pricebooks.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>
                                            <p:menuitem value="Inquiries" url="http://localhost:8080/MerlionERP-war/CRM/salesInquiries.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>
                                            <p:menuitem value="Quotations" url="http://localhost:8080/MerlionERP-war/CRM/quotations.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>
                                            <p:menuitem value="Purchase Orders" url="http://localhost:8080/MerlionERP-war/CRM/purchaseOrders.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>
                                            <p:menuitem value="Sales Orders" url="http://localhost:8080/MerlionERP-war/CRM/salesOrders.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>
                                            <p:menuitem value="Delivery Orders" url="http://localhost:8080/MerlionERP-war/CRM/deliveryOrdersCRM.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>
                                        </p:submenu>  
                                    </p:menu>
                                    <p:menu type="tiered" style="width:200px;font-family:Tahoma;font-size:12px">
                                        <p:submenu label="Create New" icon="ui-icon ui-icon-extlink">  
                                            <p:menuitem value="Customer" url="http://localhost:8080/MerlionERP-war/CRM/createNewCustomer.xhtml" />
                                            <p:menuitem value="Sales Lead" url="http://localhost:8080/MerlionERP-war/CRM/createNewSalesLead.xhtml" /> 
                                            <p:menuitem value="Contact" url="http://localhost:8080/MerlionERP-war/CRM/createNewContact.xhtml" />
                                            <p:menuitem value="Inquiry" url="http://localhost:8080/MerlionERP-war/CRM/addSalesInquiry.xhtml"/>
                                            <p:menuitem value="Quotation" url="http://localhost:8080/MerlionERP-war/CRM/addQuotation.xhtml"/>
                                            <p:menuitem value="Purchase Order" url="http://localhost:8080/MerlionERP-war/CRM/addPurchaseOrder.xhtml"/>
                                            <p:menuitem value="Sales Order" url="http://localhost:8080/MerlionERP-war/CRM/addSalesOrder.xhtml"/>
                                            <p:menuitem value="Delivery Order" url="http://localhost:8080/MerlionERP-war/CRM/addDeliveryOrder.xhtml"/>      
                                        </p:submenu>
                                    </p:menu>
                                    <p:calendar mode="inline" style="font-size:11px;font-family:Tahoma"/>
                                </td>

                                <td style="vertical-align:top">
                                    <p:toolbar style="font-size: 11px;width: 99.5%"> 
                                        <p:toolbarGroup align="left">  
                                            <p:commandButton value="New Pricebook" update="display1" ajax="true" immediate="true"
                                                             oncomplete="addPricebookDialog.show()"
                                                             image="ui-icon ui-icon-plus"/>
                                            <p:commandButton title="Delete" image="ui-icon ui-icon-trash"
                                                             value="Delete" oncomplete="deleteDialog.show()"  />

                                        </p:toolbarGroup>  

                                    </p:toolbar> 


                                    <h:panelGrid id="display1" columns="3" style="width:100%;font-family:Tahoma;font-size:11px" >

                                        <h:outputText value="Product"/>
                                        <h:outputText value=":"/>
                                        <h:selectOneMenu id="chooseProduct" value="#{PricebookManagedBean.productId}">
                                            <f:selectItem itemLabel="Select Product" itemValue=""/>
                                            <f:selectItems value="#{PricebookManagedBean.productList}" var="products"
                                                           itemLabel ="#{products.id} - #{products.itemName}" itemValue="#{products.id}"/>
                                            <p:ajax update="choosePricebook" listener="#{PricebookManagedBean.handleProductChange}"/>
                                        </h:selectOneMenu>

                                        <h:outputText value="Choose Pricebook"/>
                                        <h:outputText value=":"/>
                                        <h:selectOneMenu id="choosePricebook" value="#{PricebookManagedBean.pricebookId}">
                                            <f:selectItem itemLabel="Select Priceboook" itemValue=""/>
                                            <f:selectItems value="#{PricebookManagedBean.pricebookList}" var="pricebook"
                                                           itemLabel="#{pricebook.id} - #{pricebook.name}" itemValue="#{pricebook.id}"/>
                                            <p:ajax update="entryTable" listener="#{PricebookManagedBean.handlePricebookChange}"/>
                                        </h:selectOneMenu>

                                    </h:panelGrid>

                                    <p:dataTable id="entryTable" value="#{PricebookManagedBean.entryList}"
                                                 var="pricebookEntry" paginator="true" rows="5"
                                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                                 rowEditListener="#{PricebookManagedBean.onEditRowPricebook}"
                                                 rowsPerPageTemplate="5,10,15" style="font-family:Tahoma;font-size:11px;width:100%"                      
                                                 emptyMessage="No data found with given criteria" widgetVar="entryTable"> 


                                        <f:facet name="header">                           
                                            <p:outputPanel style="text-align:right"  >
                                                <h:outputText value="Search all fields:"/>  
                                                <p:inputText id="globalFilter" onkeyup="entryTable.filter()" style="right:-100px;width:150px" />  
                                            </p:outputPanel>
                                        </f:facet>


                                        <p:column style="width:20px"> <!--border-left-color:transparent;border-right-color:transparent"-->    
                                            <p:rowEditor/>
                                        </p:column>

                                        <p:column headerText="Minimum Qty" sortBy="#{pricebookEntry.low}" filterBy="#{pricebookEntry.low}" 
                                                  filterStyle="width:60px" filterMatchMode="contains" >
                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{pricebookEntry.low}" />  
                                                </f:facet>  
                                                <f:facet name="input">
                                                    <p:inputText value="#{pricebookEntry.low}" style="width:100%"/>
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  


                                        <p:column headerText="Maximum Qty" sortBy="#{pricebookEntry.high}" filterBy="#{pricebookEntry.high}" filterMatchMode="contains" 
                                                  filterStyle="width:60px" >
                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{pricebookEntry.high}" />  
                                                </f:facet>
                                                <f:facet name="input">
                                                    <p:inputText value="#{pricebookEntry.high}" style="width:100%" />
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  


                                        <p:column headerText="Direct Price" sortBy="#{pricebookEntry.directPrice}" filterBy="#{pricebookEntry.directPrice}" 
                                                  filterStyle="width:60px" filterMatchMode="contains" >
                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{pricebookEntry.directPrice}" />  
                                                </f:facet>
                                                <f:facet name="input">
                                                    <p:inputText value="#{pricebookEntry.directPrice}" style="width:100%"/>
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  


                                        <p:column headerText="Wholesale Price" sortBy="#{pricebookEntry.wholesalePrice}" filterBy="#{pricebookEntry.wholesalePrice}" 
                                                  filterStyle="width:60px" filterMatchMode="contains" >
                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{pricebookEntry.wholesalePrice}" />  
                                                </f:facet>
                                                <f:facet name="input">
                                                    <p:inputText value="#{pricebookEntry.wholesalePrice}" style="width:100%"/>  
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  

                                    </p:dataTable>

                                </td></tr></table>

                        <p:dialog id="addPricebook" widgetVar="addPricebookDialog" width="800" modal="true">
                            <p:panel header="Add New Pricebook">
                                <h:panelGrid columns="3" style="font-family:Tahoma;font-size:11px">

                                    <h:outputText value="Pricebook Name"/>
                                    <h:outputText value=":"/>
                                    <p:inputText value="#{PricebookManagedBean.pricebookName}"/>

                                    <h:outputText value="Product"/>
                                    <h:outputText value=":"/>
                                    <h:selectOneMenu value="#{PricebookManagedBean.productId}">
                                        <f:selectItem itemLabel="Select Product" itemValue=""/>
                                        <f:selectItems value="#{PricebookManagedBean.productList}" var="products"
                                                       itemLabel ="#{products.id} - #{products.itemName}" itemValue="#{products.id}"/>                 
                                    </h:selectOneMenu>



                                    <h:outputLabel value="Lower Quantity Range" for="lowRange"/>
                                    <h:outputLabel value=":" style="margin-left:30px"/>
                                    <p:inputText id="lowRange" required="true"   
                                                 value="#{PricebookManagedBean.newEntry.low}" >
                                    </p:inputText>

                                    <h:outputLabel value="Upper Quantity Range" for="upperRange"/>
                                    <h:outputLabel value=":" style="margin-left:30px"/>
                                    <p:inputText id="upperRange" required="true"   
                                                 value="#{PricebookManagedBean.newEntry.high}" >
                                    </p:inputText>

                                    <h:outputLabel value="Discount for Direct Business" for="discDirect"/>
                                    <h:outputLabel value=":" style="margin-left:30px"/>
                                    <p:inputText id="discDirect" required="true"   
                                                 value="#{PricebookManagedBean.newEntry.directDisc}" >
                                    </p:inputText>

                                    <h:outputLabel value="Discount for Wholesale Business" for="discWholesale"/>
                                    <h:outputLabel value=":" style="margin-left:30px"/>
                                    <p:inputText id="discWholesale" required="true"   
                                                 value="#{PricebookManagedBean.newEntry.wholesaleDisc}" >
                                    </p:inputText>


                                </h:panelGrid>  

                                <p:commandButton  value="Add" update="newEntryList msgs @parent"  
                                                  action="#{PricebookManagedBean.reinit}" style="margin-left:200px" image="ui-icon ui-icon-plus" >  
                                    <p:collector value="#{PricebookManagedBean.newEntry}"   
                                                 addTo="#{PricebookManagedBean.newEntryList}" />  
                                </p:commandButton>  
                                <p:commandButton value="Reset" type="reset" image="ui-icon ui-icon-arrowrefresh-1-s"/>  


                                <p:outputPanel id="newEntryList">  

                                    <p:dataTable value="#{PricebookManagedBean.newEntryList}" var="entry" 
                                                 rowEditListener ="#{PricebookManagedBean.onRowEditEntry}" 
                                                 style="font-family:Tahoma;font-size:12px"  >  



                                        <p:column headerText="Lower Bound" >  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{entry.low}" />  
                                                </f:facet>
                                                <f:facet name="input">
                                                    <p:inputText value="#{entry.low}" />
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  

                                        <p:column headerText="Upper Bound" >  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{entry.high}" />  
                                                </f:facet>
                                                <f:facet name="input">
                                                    <p:inputText value="#{entry.high}" />
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  


                                        <p:column headerText="Disc for Direct Business" >  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{entry.directDisc}" />  
                                                </f:facet>
                                                <f:facet name="input">
                                                    <p:inputText value="#{entry.directDisc}" />
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  

                                        <p:column headerText="Disc for Wholesale Business" >  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{entry.wholesaleDisc}" />  
                                                </f:facet>
                                                <f:facet name="input">
                                                    <p:inputText value="#{entry.wholesaleDisc}" />
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  



                                        <p:column style="width:30px;border-left-color:transparent">    
                                            <p:rowEditor/>
                                        </p:column>

                                        <p:column>  
                                            <f:facet name="header">  
                                                <h:outputText value="Operation" />  
                                            </f:facet>  
                                            <p:commandLink value="Remove" update="newEntryList" process="@this">  
                                                <p:collector value="#{entry}"  
                                                             removeFrom="#{PricebookManagedBean.newEntryList}" />  
                                            </p:commandLink>  
                                        </p:column>  

                                    </p:dataTable>  
                                </p:outputPanel>

                                <p:panel style ="text-align:right;font-family:Tahoma;border-style:hidden; font-size:11px">
                                    <p:commandButton style="text-align:right" value="Submit" update="msgs @parent" ajax="false"
                                                     actionListener="#{PricebookManagedBean.addPricebook}"/>

                                </p:panel>
                            </p:panel>                            
                        </p:dialog>

                        <p:dialog widgetVar="deleteDialog" modal="true" width="500">
                            <h:panelGrid columns="3">

                                <h:outputText value="Product"/>
                                <h:outputText value=":"/>
                                <h:selectOneMenu id="cp1" value="#{PricebookManagedBean.productId}">
                                    <f:selectItem itemLabel="Select Product" itemValue=""/>
                                    <f:selectItems value="#{PricebookManagedBean.productList}" var="products"
                                                   itemLabel ="#{products.id} - #{products.itemName}" itemValue="#{products.id}"/>
                                    <p:ajax update="cpr" listener="#{PricebookManagedBean.handleProductChange}"/>
                                </h:selectOneMenu>


                                <h:outputText value="Choose Pricebook to be deleted"/>
                                <h:outputText value=":"/>
                                <h:selectOneMenu id="cpr" value="#{PricebookManagedBean.deletedPricebookId}">
                                    <f:selectItem itemLabel="Select Priceboook" itemValue=""/>
                                    <f:selectItems value="#{PricebookManagedBean.pricebookList}" var="pricebook"
                                                   itemLabel="#{pricebook.id} - #{pricebook.name}" itemValue="#{pricebook.id}"/>
                                    <p:ajax listener="#{PricebookManagedBean.handleDelete}"/>
                                </h:selectOneMenu>

                                <h:outputText value=""/>
                                <p:commandButton value="Delete" update="display1" actionListener="#{PricebookManagedBean.delete}" 
                                                 ajax="true" immediate="true" oncomplete="deleteDialog.hide()"/>
                                <p:commandButton value="Close" oncomplete="deleteDialog.hide()"/>

                            </h:panelGrid>
                        </p:dialog>

                    </div>

                    <div id="bottom" class="bottom">
                        <h:graphicImage value="/image/merlionfooter.jpg"/>
                    </div>
                </h:form>
            </h:body>
        </f:view>
    </f:view>
</html>